/*
 * This file is part of Cadmium.
 * Copyright (C) 2007-2010 Xavier Clerc.
 *
 * Cadmium is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Cadmium is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.x9c.cadmium.support.values;

import fr.x9c.cadmium.kernel.Value;
import fr.x9c.cadmium.primitives.cadmium.Cadmium;

/**
 * This class defines values of the <i>Cadmium.java_object</i>,
 * <i>Cadmium.java_class</i>, <i>Cadmium.java_constructor</i>,
 * <i>Cadmium.java_field</i>, and <i>Cadmium.java_method</i> types.
 *
 * @author <a href="mailto:cadmium@x9c.fr">Xavier Clerc</a>
 * @version 1.0
 * @since 1.0
 */
public final class JavaObject implements ToValue {

    /** The embedded value. */
    private Object value;

    /**
     * Constructs a Java value.
     * @param o object - should not be <tt>null</tt>
     */
    public JavaObject(final Object o) {
        assert o != null : "null o";
        this.value = o;
    } // end constructor(Object)

    /**
     * {@inheritDoc}
     */
    @Override
    public Value toValue() {
        return Cadmium.createObject(this.value);
    } // end method 'toValue()'

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return this.value.hashCode();
    } // end method 'hashCode()'

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj instanceof JavaObject) {
            final JavaObject that = (JavaObject) obj;
            return this.value.equals(that.value);
        } else {
            return false;
        } // end if/else
    } // end method 'equals(Object)'

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return this.value.toString();
    } // end method 'toString()'

} // end class 'JavaObject'
